package com.kecheng.dao;

import com.kecheng.hibernate.BaseDao;
import com.kecheng.pojo.Skuclassify4;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class Skuclassify4Dao extends BaseDao{

	public List<Skuclassify4> findall() {
		List<Skuclassify4> skuclassify4s;
		skuclassify4s = (List<Skuclassify4>) this.getHibernateTemplate().find("from Skuclassify4 order by id desc");
		return skuclassify4s;
	}
	public List<Skuclassify4> findBySkuclassifyid3(int skuclassifyid3) {
		List<Skuclassify4> skuclassify4s= (List<Skuclassify4>) this.getHibernateTemplate().find("from Skuclassify4 where skuclassifyid3=?",skuclassifyid3);
		return skuclassify4s;
	}
	public Skuclassify4 findById(int id) {
		List<Skuclassify4> skuclassify4s= (List<Skuclassify4>) this.getHibernateTemplate().find("from Skuclassify4 where id = ?",id);
		if(skuclassify4s.size()>0){
			Skuclassify4 skuclassify4=skuclassify4s.get(0);
			return skuclassify4;
		}
		return null;
	}
	
	public List<Skuclassify4> findmh(String name,int refid) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria=DetachedCriteria.forClass(Skuclassify4.class);
		criteria.add(
				Restrictions.ilike("name", name, MatchMode.ANYWHERE));	
		criteria.addOrder(Order.desc("id"));
		criteria.add(Restrictions.eq("skuclassifyid3", refid));
		List<Skuclassify4> skuclassify4s= (List<Skuclassify4>) this.getHibernateTemplate().findByCriteria(criteria);
		return skuclassify4s;
	}
	public void add(Skuclassify4 skuclassify4) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().save(skuclassify4);
	}
	public void del(Skuclassify4 skuclassify4) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().delete(skuclassify4);
	}

}
